package com.upay.android.client.handler;

import java.util.List;

import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.upay.android.client.R;
import com.upay.android.client.activity.AbstractUPayActivity;
import com.upay.android.client.activity.GroupAvailableUsersActivity;
import com.upay.android.client.adapter.AvailableUserArrayAdapter;
import com.upay.domain.account.User;
import com.upay.domain.response.ResponseEnvelope;

public class GroupAvailableUsersCallbackHandler extends AbstractCallbackHandler<List<User>> {
	
	/* ---- Constants ---- */
	
	/* ---- Instance Variables ---- */
	private List<User> users = null;
	private Long groupId = null;
	
	/* ---- Constructors ---- */

	public GroupAvailableUsersCallbackHandler(AbstractUPayActivity context) {
		this.context = context;
	}
	
	/* ---- Business Methods ---- */
	

	@Override
	public void handleResponse(ResponseEnvelope<List<User>> response) {
		users = response.getResponseBody().getResponseObject();
		ArrayAdapter<User> adapter = new AvailableUserArrayAdapter(getContext(), users);
		ListView userList = (ListView)getContext().findViewById(R.id.groupavailableuserlist);
		userList.setAdapter(adapter);
		userList.setOnItemClickListener(((GroupAvailableUsersActivity)this.context).getMenuListener());
	}

	@Override
	public void handleValidationException(ResponseEnvelope<List<User>> response) {
		// Handle the exception for not providing correct userid and token;
	}

	/* ---- Getters and Setters ---- */
	
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public Long getGroupId() {
		return groupId;
	}

	public void setGroupId(Long groupId) {
		this.groupId = groupId;
	}

}
